package machine.api;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * 随机壁纸api
 *
 * @author zhanghui145
 * @date 2021/12/25 16:52
 * @since 1.0.0
 */
@Service
public class WallpaperApi {

    private static final List<String> LX = new ArrayList<>();
    private static final String URI = "https://api.btstu.cn/sjbz/api.php?lx=";

    @PostConstruct
    public void init(){
        LX.add("meizi");
        LX.add("dongman");
        LX.add("fengjing");
    }
    public String randomWallpaper() {
        try {
            int x = RandomUtil.randomInt(0,2);
            HttpResponse response = HttpRequest.post(URI + LX.get(x)).execute();
            return response.header("location");
        } catch (Exception e) {
            throw new RuntimeException("查询壁纸失败~");
        }
    }
}
